<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Simulation scripts</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>

<body>

<div align="center">
<table class=allEncompassingTable >
 <tr>
  <td >
<p><a href="../index.html" TARGET="_top"><img src="images/homeImg.png"></a></p>



<h1>Simulation scripts</h1>

<p>Simulation <a href="scripts.htm">scripts</a> play the central role in a simulation, and are only executed while a simulation is running. There two types of simulation scripts: </p>

<li><a href="mainScript.htm">The main script</a>: by default, each <a href="scenes.htm">scene</a> has a main script that handles all the functionality (that is is charge of calling child scripts (see hereafter)). Without main script, a <a href="simulation.htm">simulation</a> cannot run. The main script can be customized, but it is preferable to do all the customization work in child scripts.<br>
</li>

<li><a href="childScripts.htm">Child scripts</a>: each <a href="objects.htm">scene object</a> can be associated with a child script that can handle a specific part of a simulation. The most common use for a child script is to have it control a <a href="models.htm">model</a> (e.g. a robot). Since child scripts  are attached to scene objects (i.e. they are <em>associated</em> scripts), they will also be duplicated during a copy-and-paste operation, which is an important feature that allows a simulation scene to be easily scalable. <em>Associated</em> scripts form the basis of CoppeliaSim's distributed control architecture.</li>

<p>Following are the main differences between the main script and a child script:</p>

<li>there can only be one main script. There can be an unlimited number of child scripts.</li>

<li>the main script is independent and should preferably not be customized. Child scripts are associated with scene objects and should be customized.</li>

<li>the main script is never duplicated in a copy/paste operation of scene objects. Child scripts will duplicate themselves together with their associated scene object.</li>

<li>child scripts support a few more <a href="callbackFunctions.htm">callback functions</a> than the main script.</li>


<p>Simulation scripts, and all scripts in general, are mainly invoked via <a href="callbackFunctions.htm#systemCallbacks">system callback functions</a> by CoppeliaSim, and follow a precise<a href="scriptExecution.htm"> execution order </a>in relation with other script types. They can <a href="threadedAndNonThreadedCode.htm">run threaded or non-threaded</a>.</p>

<br>
<br>
 </tr>
</table> 
</div>  
  
  
</body>

</html>
